//
//  BackgroundMountain.m
//  TheifRunning
//
//  Created by Lion on 6/16/14.
//  Copyright (c) 2014 Apportable. All rights reserved.
//

#import "BackgroundMountain.h"

@implementation BackgroundMountain{
    CCNode *_mountain;
    CCPhysicsNode *_physicNode;
    CGFloat scrollSpeed;
}

- (void) didLoadFromCCB{
    scrollSpeed = 20;
}

- (void)update:(CCTime)delta{
    scrollSpeed += delta*10;
    // get the world position of the ground
    CGPoint mountainWorldPosition = [_physicNode convertToWorldSpace:_mountain.position];
    // get the screen position of the ground
    CGPoint mountainScreenPosition = [self convertToNodeSpace:mountainWorldPosition];
    // if the left corner is one complete width off the screen, move it to the right
    if (mountainScreenPosition.x <= (-1 * _mountain.contentSize.width)) {
        _mountain.position = ccp(-_physicNode.position.x + 580, _mountain.position.y);
    }

    //physicNode
    _physicNode.position = ccp(_physicNode.position.x - (scrollSpeed *delta), _physicNode.position.y);
}
@end
